﻿@*
    For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
*@
@{
    Layout = "_Layout";
}
<body class="layui-anim layui-anim-up">

    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-block">
                <input type="text" name="Title" lay-verify="required" autocomplete="off" placeholder="请输入标题" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">类型</label>
            <div class="layui-input-block">
                <select name="type" asp-items="@Html.GetEnumSelectList(typeof(zhangmenren.Models.Enums.BannerType))"></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">链接地址</label>
            <div class="layui-input-block">
                <input type="text" name="HrefUrl" lay-verify="required|url" placeholder="请输入链接地址" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-block">
                <input type="checkbox" checked="" name="State" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF">
            </div>
        </div>
        <div class="layui-upload">
            <label class="layui-form-label">请上传图片</label>
            <input type="hidden" name="ImgUrl" lay-verify="required" id="ImgUrl" value="" />
            <button type="button" class="layui-btn" id="test1">上传图片</button>
            <div class="layui-input-block">
                <img class="layui-upload-img" id="demo1" style="width:300px;height:150px;visibility:hidden;margin:10px 0;">
                <p id="demoText"></p>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">描述</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容" name="Describe" lay-verify="required" class="layui-textarea"></textarea>
            </div>
        </div>
        <!--<div class="layui-form-item layui-form-text">
      <label class="layui-form-label">编辑器</label>
      <div class="layui-input-block">
        <textarea class="layui-textarea layui-hide" name="content" lay-verify="content" id="LAY_demo_editor"></textarea>
      </div>
    </div>-->
        <div class="layui-form-item" align="center">
            <button class="layui-btn layui-btn-normal btnEdit" lay-submit="" lay-filter="btnEdit" style="display:none;">操作</button>
        </div>
    </form>

    <script>
        layui.use(['form','layer','upload'], function(){
        $=layui.jquery;
          var form = layui.form
          ,layer = layui.layer;
        var upload=layui.upload;



        //普通图片上传
  var uploadInst = upload.render({
    elem: '#test1'
    ,url: '/Admin/Banner/UploadFilesAjax'
    ,before: function(obj){
      //预读本地文件示例，不支持ie8
      obj.preview(function(index, file, result){

        $('#demo1').attr('src', result); //图片链接（base64）
        $('#demo1').css({ visibility: "visible" })

      });
    }
    ,done: function(res){
      //如果上传失败
      if(res.code > 0){
        return layer.msg('上传失败');
      }else{
        $('#ImgUrl').val(res.data.src);
      }
      //上传成功
    }
    ,error: function(){
      //演示失败状态，并实现重传
      var demoText = $('#demoText');
      demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-xs demo-reload">重试</a>');
      demoText.find('.demo-reload').on('click', function(){
        uploadInst.upload();
      });
    }
  });


                  //监听提交
			form.on('submit(btnEdit)', function(data){

				var obj = data.field;
				if (obj.State="on") {
					obj.State = true;
				}
				HsCms.AjaxJson("/Admin/Banner/Add", "post", obj, function (result) {
				  if (result.state === "OK") {
					  HsCms.CloseFrame();
					  HsCms.ParentLoad("banner");
				  }
				  HsCms.ParentMsg(result.msg);
			  });



            @*//发异步，把数据提交给php
            layer.alert("增加成功", {icon: 6},function () {
                // 获得frame索引
                var index = parent.layer.getFrameIndex(window.name);
                //关闭当前frame
                parent.layer.close(index);
            });*@
            return false;
          });



       });
    </script>

</body>